package com.lmf.annotation;

import com.lmf.annotation.bean.MathCalculator;
import com.lmf.annotation.config.MyConfigOfAspects;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Aop编程：测试
 */
public class AOPTest_BeanAspects {
    @Test
    public void test_1(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfigOfAspects.class);
        //不能新创建一个mathCalculator对象，否则aop不会对该对象生效
//        MathCalculator mathCalculator1=new MathCalculator();
//        int div = mathCalculator1.div(6, 3);
//        System.out.println(div);
//        System.out.println("------------------------");
        //必须从spring容器中获取该对象，这个对象才会被增强
        MathCalculator mathCalculator = context.getBean("mathCalculator", MathCalculator.class);
        int i = mathCalculator.div(6, 3);
        System.out.println(i);
    }
}
